import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

// import ServiceForm from '@/pages/ServiceForm.vue'
import DispatchPage from "@/pages/Dispatch";
import MonitorPage from "@/pages/Monitor";
import ManagementPage from "@/pages/Management";
import AnalyzePage from "@/pages/Analyze";
import Home from "@/pages/Home";
import Index from "@/pages/index.vue";
import Login from "@/pages/Login";

const routes = [
  {
    path: "/",
    redirect: "/index",
  },
  {
    path: "/index",
    name: "Index",
    redirect: "/index/home",
    component: Index,
    children: [
      {
        path: "/index/home",
        name: "HomePage",
        component: Home,
      },
      {
        path: "/index/dispatch",
        name: "dispatchPage",
        component: DispatchPage,
      },
      {
        path: "/index/monitor",
        name: "MonitorPage",
        component: MonitorPage,
      },
      {
        path: "/index/management",
        name: "managementPage",
        component: ManagementPage,
      },
      {
        path: "/index/analyze",
        name: "analyzePage",
        component: AnalyzePage,
      },
    ],
  },
  {
    path:"/login",
    name: "Login",
    component:Login,
  }
];

const router = new VueRouter({
  mode: "history",
  routes,
});

// push重写方法
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

// 同时重写 replace 方法
const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch((err) => err);
};

export default router;
